package alertPeopleMsg

import (
	"context"
	"devops-super/api/alerts/v1"
	"devops-super/internal/model/entity"
	"devops-super/internal/service"
	"github.com/gogf/gf/v2/os/gtime"
)

// GetPageLst 分页获取告警通知日志列表
func (*ControllerV1) GetPageLst(ctx context.Context, req *v1.AlertPeopleMsgGetPageLstReq) (res *v1.AlertPeopleMsgGetPageLstRes, err error) {
	res = &v1.AlertPeopleMsgGetPageLstRes{}
	res.PageLstRes, err = service.AlertPeopleMsg().GetPageLst(ctx, req)
	return
}

// Add 新增告警通知日志
func (*ControllerV1) Add(ctx context.Context, req *v1.AlertPeopleMsgAddReq) (res *v1.AlertPeopleMsgAddRes, err error) {
	alertPeopleMsg := &entity.AlertPeopleMsgsDemo{
		AlertLogId: req.AlertLogId,
		PeopleId:   req.PeopleId,
		Msg:        req.Msg,
		NoticeType: req.NoticeType,
		Status:     req.Status,
		StatusMsg:  req.StatusMsg,
		DeptId:     req.DeptId,
		CreatedAt:  gtime.Now(),
	}
	err = service.AlertPeopleMsg().Add(ctx, alertPeopleMsg)
	return
}

// Upt 更新告警通知日志
func (*ControllerV1) Upt(ctx context.Context, req *v1.AlertPeopleMsgUptReq) (res *v1.AlertPeopleMsgUptRes, err error) {
	alertPeopleMsg := &entity.AlertPeopleMsgsDemo{
		Id:         req.Id,
		AlertLogId: req.AlertLogId,
		PeopleId:   req.PeopleId,
		Msg:        req.Msg,
		NoticeType: req.NoticeType,
		Status:     req.Status,
		StatusMsg:  req.StatusMsg,
		DeptId:     req.DeptId,
		UpdatedAt:  gtime.Now(),
	}
	err = service.AlertPeopleMsg().Upt(ctx, alertPeopleMsg)
	return
}

// UptStatus 更新告警通知日志状态
func (*ControllerV1) UptStatus(ctx context.Context, req *v1.AlertPeopleMsgUptStatusReq) (res *v1.AlertPeopleMsgUptStatusRes, err error) {
	err = service.AlertPeopleMsg().UptStatus(ctx, req.Id, req.Status, req.StatusMsg)
	return
}

// Del 删除告警通知日志
func (*ControllerV1) Del(ctx context.Context, req *v1.AlertPeopleMsgDelReq) (res *v1.AlertPeopleMsgDelRes, err error) {
	err = service.AlertPeopleMsg().Del(ctx, req.Id)
	return
}

// GetOne 获取单条告警通知日志
func (*ControllerV1) GetOne(ctx context.Context, req *v1.AlertPeopleMsgGetOneReq) (res *v1.AlertPeopleMsgGetOneRes, err error) {
	res1, err := service.AlertPeopleMsg().GetOne(ctx, req.Id)
	if err != nil {
		return
	}
	res = new(v1.AlertPeopleMsgGetOneRes)
	res.Info = res1
	return
}

// GetOptions 获取表单选项
func (*ControllerV1) GetOptions(ctx context.Context, req *v1.AlertPeopleMsgGetOptionsReq) (res *v1.AlertPeopleMsgGetOptionsRes, err error) {
	res, err = service.AlertPeopleMsg().GetOptions(ctx, req)
	return
}

// BatchDel 批量删除告警通知日志
func (*ControllerV1) BatchDel(ctx context.Context, req *v1.AlertPeopleMsgBatchDelReq) (res *v1.AlertPeopleMsgBatchDelRes, err error) {
	err = service.AlertPeopleMsg().BatchDel(ctx, req.Ids)
	return
}